// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SourceFile

package com.sgame.android.data;

import com.sgame.android.data.TunnelTransmittable;
import com.sgame.android.data.Tunnel;
import java.util.*;
import org.json.*;

// Referenced classes of package com.mobage.us.android.data:
//            RewardCampaignCode

public class RewardCampaign
    implements TunnelTransmittable
{
    public static enum Field
    {
    	UID, REDEMPTIONS, STARTS_AT, ENDS_AT, EXPIRES_AT, PAYLOAD, CODES
    }


    public RewardCampaign()
    {
        a = null;
        b = 0;
        c = 0;
        d = 0;
        e = 0;
        f = null;
        g = null;
    }

    public String getUid()
    {
        return a;
    }

    public void setUid(String uid)
    {
        a = uid;
    }

    public String getId()
    {
        return a;
    }

    public void setId(String uid)
    {
        a = uid;
    }

    public int getRedemptions()
    {
        return b;
    }

    public void setRedemptions(int redemptions)
    {
        b = redemptions;
    }

    public int getStartsAt()
    {
        return c;
    }

    public void setStartsAt(int starts_at)
    {
        c = starts_at;
    }

    public int getEndsAt()
    {
        return d;
    }

    public void setEndsAt(int ends_at)
    {
        d = ends_at;
    }

    public int getExpiresAt()
    {
        return e;
    }

    public void setExpiresAt(int expires_at)
    {
        e = expires_at;
    }

    public String getPayload()
    {
        return f;
    }

    public void setPayload(String payload)
    {
        f = payload;
    }

    public List getCodes()
    {
        return g;
    }

    public void setCodes(List codes)
    {
        g = codes;
    }

    public void setFromJson(JSONObject json)
    {
        a = json.optString(Field.UID.name());
        b = json.optInt(Field.REDEMPTIONS.name());
        c = json.optInt(Field.STARTS_AT.name());
        d = json.optInt(Field.ENDS_AT.name());
        e = json.optInt(Field.EXPIRES_AT.name());
        f = json.optString(Field.PAYLOAD.name());
        g = new ArrayList();
        JSONArray jarr;
        if((jarr = json.optJSONArray(Field.CODES.name())) != null)
            try
            {
                for(int i = 0; i < json.length(); i++)
                {
                	JSONObject obj;
                	RewardCampaignCode reward;
                    obj = jarr.getJSONObject(i);
                    obj.put(Field.UID.name(), ((JSONObject) (obj)).get("code"));
                    reward = new RewardCampaignCode();
                    reward.setFromJson(jarr.getJSONObject(i));
                    g.add(reward);
                }

                return;
            }
            catch(JSONException jsonexception)
            {
                throw new RuntimeException(jsonexception);
            }
        else
            return;
    }

    public JSONObject toJson()
    {
        JSONObject jsonobject = new JSONObject();
        try
        {
            jsonobject.put(Field.UID.name(), a);
            jsonobject.put(Field.REDEMPTIONS.name(), b);
            jsonobject.put(Field.STARTS_AT.name(), c);
            jsonobject.put(Field.ENDS_AT.name(), d);
            jsonobject.put(Field.EXPIRES_AT.name(), e);
            jsonobject.put(Field.PAYLOAD.name(), f);
            JSONArray jsonarray = new JSONArray();
            RewardCampaignCode rewardcampaigncode;
            for(Iterator iterator = g.iterator(); iterator.hasNext(); jsonarray.put(rewardcampaigncode.toJson()))
                rewardcampaigncode = (RewardCampaignCode)iterator.next();

            jsonobject.put(Field.CODES.name(), jsonarray);
        }
        catch(JSONException jsonexception)
        {
            throw new RuntimeException(jsonexception);
        }
        return jsonobject;
    }

    public String toJsonStringForTunnel()
    {
        JSONObject jsonobject = new JSONObject();
        try
        {
            jsonobject.put(Field.UID.name(), a);
            jsonobject.put(Field.REDEMPTIONS.name(), b);
            jsonobject.put(Field.STARTS_AT.name(), c);
            jsonobject.put(Field.ENDS_AT.name(), d);
            jsonobject.put(Field.EXPIRES_AT.name(), e);
            jsonobject.put(Field.PAYLOAD.name(), f);
            JSONArray jsonarray = new JSONArray();
            RewardCampaignCode rewardcampaigncode;
            for(Iterator iterator = g.iterator(); iterator.hasNext(); jsonarray.put(rewardcampaigncode.toJsonStringForTunnel()))
                rewardcampaigncode = (RewardCampaignCode)iterator.next();

            jsonobject.put(Field.CODES.name(), jsonarray);
        }
        catch(JSONException jsonexception)
        {
            throw new RuntimeException(jsonexception);
        }
        return Tunnel.toString("RewardCampaign", jsonobject);
    }

    public void updateWithJsonObjectFromTunnel(JSONObject jsonObject)
    {
        setFromJson(jsonObject);
    }

    private String a;
    private int b;
    private int c;
    private int d;
    private int e;
    private String f;
    private List g;
}
